package controller;

import dao.ShopDao;
import dao.auditDao;
import dao.reviewDao;
import entity.Audit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.stock;
import service.StockDao;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/auditAndreview")
public class auditAndreview {
    @Autowired
    private auditDao auditDao;
    @Autowired
    private dao.reviewDao reviewDao;
    @Autowired
    private ShopDao shopDao;
    @Autowired
    private StockDao stockDao;//service下的
    /**
     * 展示采购审核的信息
     */
    public Map<String,Object> showAudit(int StateId,String seat,String lasttime,String times,int offset,int limit){
        Map<String,Object> map=new HashMap<>();
        map.put("rows",auditDao.showAudit(StateId,seat,lasttime,times,offset,limit));
        map.put("total",auditDao.totalAudit(StateId,seat,lasttime,times));
        return map;
    }

    /**
     * 展示采购审核的信息
     */
    @RequestMapping("/showAudits")
    @ResponseBody
    public Map<String,Object> showAudits(int StateId,String seat,String lasttime,String times,int offset,int limit){
        return showAudit( StateId, seat, lasttime, times,offset, limit);
    }
    /**
     * 根据单号展示采购详情信息
     */
    @RequestMapping("/showReview")
    @ResponseBody
    public Map<String,Object> showReview(String seat,int offset,int limit,int StateId){
        Map<String,Object> map=new HashMap<>();
        if(seat!=null&&seat!=""){
            map.put("rows",reviewDao.showReview(seat,offset,limit));
            map.put("total",reviewDao.totalReview(seat));
        }else{
            Audit audit=auditDao.showAuditOne(StateId);
            if(audit!=null){
                map.put("rows",reviewDao.showReview(audit.getSeat(),offset,limit));
                map.put("total",reviewDao.totalReview(audit.getSeat()));
            }
        }
        return map;
    }

    /**
     * 采购审核
     *  * @param StateId//审核单号
     * @param StateId//状态编号
     * @param seat//根据查询单号信息
     * @param lasttime//开始时间
     * @param times//结束时间
     * @param offset//分页第几页
     * @param limit//每页显示几条
     * @return
     */
    @RequestMapping("/upStateId")
    @ResponseBody
    public Map<String,Object> upStateId(String seats, int StateId, String seat, String lasttime, String times, int offset, int limit, HttpServletRequest request){
        stockDao.ruku(seats,request);
        return showAudit( StateId, seat, lasttime, times,offset, limit);
    }

}
